package chapter01_Arr

import scala.collection.mutable

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test08_MutableMap
 * Package: chapter01_Arr
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 *          Date: 2023-07-14
 *          Time: 23:04
 */

//可变Map
object Test08_MutableMap {
  def main(args: Array[String]): Unit = {
    //创建可变Map
    val map1: mutable.Map[String, Int] =
      mutable.Map("a" -> 12, "b" -> 23, "c" -> 4)

    println(map1) //Map(b -> 23, a -> 12, c -> 4)
    println(map1.getClass) //class scala.collection.mutable.HashMap
    //没有$ 和数字


    //添加元素
    map1.put("hello",909)
    map1.put("c",123) //已经存在的就修改
    println(map1)

    //符号添加
    map1 += (("e",7))
    println(map1)

    //删除元素
    map1.remove("e")

    map1 -= "hello"
    println(map1)

    //合并map
    val map2 = Map("pp" -> 123,"bb" -> 456)
    //++= 前面变化 后面不变
    map1 ++= map2
    println(map1) //Map(b -> 23, bb -> 456, pp -> 123, a -> 12, c -> 123)
    //可变和 不可变直接 ++=
    //调用 ++ 生成新的Map集合


  }
}
